package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.MedicalInsuranceInfo;
import com.ruoyi.project.service.IMedicalInsuranceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 医疗保险Controller
 * 
 * @author xiao6ming6
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/project/medicalInsurance")
public class MedicalInsuranceInfoController extends BaseController
{
    @Autowired
    private IMedicalInsuranceInfoService medicalInsuranceInfoService;

    /**
     * 查询医疗保险列表
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalInsuranceInfo medicalInsuranceInfo)
    {
        startPage();
        List<MedicalInsuranceInfo> list = medicalInsuranceInfoService.selectMedicalInsuranceInfoList(medicalInsuranceInfo);
        return getDataTable(list);
    }

    /**
     * 导出医疗保险列表
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:export')")
    @Log(title = "医疗保险", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalInsuranceInfo medicalInsuranceInfo)
    {
        List<MedicalInsuranceInfo> list = medicalInsuranceInfoService.selectMedicalInsuranceInfoList(medicalInsuranceInfo);
        ExcelUtil<MedicalInsuranceInfo> util = new ExcelUtil<MedicalInsuranceInfo>(MedicalInsuranceInfo.class);
        util.exportExcel(response, list, "医疗保险数据");
    }

    /**
     * 获取医疗保险详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(medicalInsuranceInfoService.selectMedicalInsuranceInfoById(id));
    }

    /**
     * 新增医疗保险
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:add')")
    @Log(title = "医疗保险", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalInsuranceInfo medicalInsuranceInfo)
    {
        return toAjax(medicalInsuranceInfoService.insertMedicalInsuranceInfo(medicalInsuranceInfo));
    }

    /**
     * 修改医疗保险
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:edit')")
    @Log(title = "医疗保险", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalInsuranceInfo medicalInsuranceInfo)
    {
        return toAjax(medicalInsuranceInfoService.updateMedicalInsuranceInfo(medicalInsuranceInfo));
    }

    /**
     * 删除医疗保险
     */
    @PreAuthorize("@ss.hasPermi('project:medicalInsurance:remove')")
    @Log(title = "医疗保险", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(medicalInsuranceInfoService.deleteMedicalInsuranceInfoByIds(ids));
    }

    /**
     * 导入医疗保险数据
     */
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<MedicalInsuranceInfo> util = new ExcelUtil<>(MedicalInsuranceInfo.class);
        List<MedicalInsuranceInfo> medicalInsuranceList = util.importExcel(file.getInputStream());
        String message = medicalInsuranceInfoService.importMedicalInsurance(medicalInsuranceList, updateSupport);
        return success(message);
    }
}
